<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let p = new Promise((resolve, reject) => {
      resolve('成功了')
    })

    p
      .then(res => { console.log(res); })
      .catch(err => { })
      .finally(() => {
        console.log('最后都要运行这个回调');
      })

    // Promise.all()  Promise.race()

    let p1 = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve('成功了111')
      }, 1000)
    })
    let p2 = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve('成功了222')
      }, 5000)
    })

    // all会等所有的异步执行完，然后把结果放到一个数组里面
    // Promise.all([p1, p2]).then(res => {
    //   console.log(res);
    // })

    // race不会等所有的结果，谁先出结果就先展示谁的结果
    Promise.race([p1, p2]).then(res => {
      console.log(res);
    })


  </script>
</body>

</html>